import { Component, OnInit, Input, Renderer2, ElementRef } from "@angular/core";
import { Iwe7UrlService } from "../iwe7-tools/public_api";
import { HttpClient } from "@angular/common/http";

@Component({
  selector: "iwe7-form-preview",
  templateUrl: "./iwe7-form-preview.component.html",
  styleUrls: ["./iwe7-form-preview.component.scss"]
})
export class Iwe7FormPreviewComponent implements OnInit {
  @Input() id: string;
  detail: any = {};

  height: number;
  constructor(
    private url: Iwe7UrlService,
    private http: HttpClient,
    private render: Renderer2,
    public ele: ElementRef
  ) {}

  ngOnInit() {
    this.getDetail().subscribe(res => {
      this.detail = res;
    });
    this.height = document.documentElement.clientHeight;
    this.render.setStyle(this.ele.nativeElement, "height", this.height + "px");
  }

  getDetail() {
    let url = this.url.getOpenUrl("formBuilder/getDetail", { id: this.id });
    return this.http.get(url);
  }
}
